package com.ai.web.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ai.web.service.AppUserService;
import com.ai.web.vo.AppUserV;
import com.ai.web.vo.ResultModel;
import com.tiny.persistence.domain.AppUser;
import com.tiny.persistence.repository.AppUserRepo;
/**
 * App用户
* @ClassName: BgAppUserServiceImpl 
* @Description: TODO 
* @author:  
* @date: 2014年3月28日
*
 */
@Service("appUserService")
public class AppUserServiceImpl extends BaseServiceImpl<AppUser, Integer, AppUserV> implements AppUserService  {

	@Autowired
	private AppUserRepo appUserRepo;
	
	@Autowired
	public AppUserServiceImpl(AppUserRepo appUserRepo) {
		super(appUserRepo);
	}

	public AppUserV getAppUser(int userId) throws Exception {
		return getT(userId);
	}

	public ResultModel saveAppUser(AppUserV AppUserV) throws Exception {
		
		AppUserV saveV = saveT(AppUserV);
		
		ResultModel rm = new ResultModel();
		rm.setData(saveV);
		rm.setSuccessCode();
		
		return rm;
	}

	public ResultModel deleteAppUsers(List<Integer> userIds) throws Exception {
		deleteTs(userIds);
		
		ResultModel rm = new ResultModel();
		rm.setSuccessCode();
		rm.setMsg("删除成功！");
		
		return rm;
	}

	public AppUserV getAppUserByPhone(String phone) throws Exception {
		
		AppUser appUser = appUserRepo.findByMobilePhone(phone);
		if (appUser == null) {
			return null;
		} else {
			AppUserV appUserV = new AppUserV();
			BeanUtils.copyProperties(appUser, appUserV);
			
			return appUserV;
		}
	}
}
